import store from '@/store'
import { locateData } from '@/assets/json/locate'
var CryptoJS = require("crypto-js");
export default {
  // 全局路径
  // apiServer: 'http://dev_console_api.ihibuilding.cn/',
  apiServer: 'http://test_console_api.ihibuilding.cn',
  // apiServer:'http://192.168.33.84:8201',
  /* apiServer () {
    return '/'
  }, */
  imageServer: '/',
  // 本地存储
  setStorage (name, content) {
    if (!name) return
    if (typeof content !== 'string') {
      content = JSON.stringify(content)
    }
    window.localStorage.setItem(name, content)
  },
  getStorage (name) {
    if (!name) return
    let content = window.localStorage.getItem(name)
    return JSON.parse(content)
  },
  removeStorage (name) {
    if (!name) return
    window.localStorage.removeItem(name)
  },
  getAuth (name) {
    let mainAuth = store.state.pageAuth
    let authList = mainAuth.children_list
    let flag = false
    authList.map((item) => {
      if (item.object_no === name) {
        flag = true
      }
    })
    return flag
  },
  // CryptoJS解密
  decrypt(text) {
    let dectext = CryptoJS.AES.decrypt(text, process.env.AES_SERCERT, {
      mode: CryptoJS.mode.ECB, // 加密模式
      padding: CryptoJS.pad.Pkcs7 // 填充方式
    });
    return dectext.toString(CryptoJS.enc.Utf8);
  },
  // 通过省市区名称获得省市区编号
  getLocationNo (province, city, area) {
    let provinceNo = ''
    let cityNo = ''
    let areaNo = ''
    let cityList = []
    let areaList = []
    for (let item of locateData) {

      if (item.name === province) {
        provinceNo = item.code
        cityList = item.children || []
        break
      }
    }
    for (let item of cityList) {
      if (item.name === city) {
        cityNo = item.code
        areaList = item.children || []
        break
      }
    }
    for (let item of areaList) {
      if (item.name === area) {
        areaNo = item.code
        break
      }
    }
    let res = {
      provinceNo: provinceNo,
      cityNo: cityNo,
      areaNo: areaNo
    }
    return res
  },
  // 打印excel文件表格样式
  printFileStyle: `

    .h-table {
      width: 297mm;
      margin: 0 auto;
      padding: 20px;
    }
  
    .table-header {
      border: 1px solid;
      width: 100%;
      font-size: 15px;
      text-align: center;
      border-collapse: collapse;
      table-layout: fixed;
    }
  
    .table-header td,
    .table-header th {
      border-bottom: 1px solid #000 !important;
      border-right: 1px solid #000 !important;
      text-align: center;
    }
  
    .table-body {
      border-top: 1px solid;
      border-left: 1px solid;
      margin: 5px 2px 2px;
      table-layout: fixed;
      border-collapse: collapse;
      border-spacing: 0;
      width: calc(100% - 4px);
    }
  
    .table-body td,
    .table-body th {
      text-align: center;
    }
  
    .table-bottom {
      margin: 10px 2px 2px;
      height: 150px;
      border: 1px solid #000 !important;
    }
  
    .table-bottom .content {
      margin: 2px 10px 2px 2px;
      color: #999;
    }`,
}
